package com.facebank.usersupport.aop;

import com.facebank.usersupport.model.RestModel;
import com.facebank.usersupport.util.SessionUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Auther: yaozun
 * @Date: 2018/4/23 0023 15:35
 * @Description:
 */
@Aspect
@Component
public class BeanHelper {
    private final Logger log = LoggerFactory.getLogger(BeanHelper.class);

    @Pointcut("within(com.facebank.usersupport.controller.ShopController)")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object trackInfo(ProceedingJoinPoint pjp) throws Throwable {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        HttpSession session = request.getSession();
        if (SessionUtil.getAssociatorId(session) == null || SessionUtil.getAssociatorId(session) == "") {
            log.info("-------------没有登录-------------");
            return new RestModel("205","用户未登录");
        }
        return pjp.proceed();
    }
}
